//
//  HomeMessageTableViewCell.m
//  DriverFramework
//
//  Created by Qianxia on 2017/1/4.
//  Copyright © 2017年 黄旺鑫. All rights reserved.
//

#import "HomeMessageTableViewCell.h"
#import <QXDriverConfiguration/QXDriverConfiguration.h>
#import "HomeMessageInformationListOfCenterModel.h"

@implementation HomeMessageTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.messageIconImageView.image = [QXDriverConfiguration imageWithName:@"public_icon_xitong_message"];
    [self.closeButton setImage:[QXDriverConfiguration imageWithName:@"public_icon_message_close"] forState:UIControlStateNormal];
    
}

- (void)setValueWithHomeMessageInformationListOfCenterModel:(HomeMessageInformationListOfCenterModel *)model {
    
    // 设置消息类型
    if (model.type) {
        
        switch (model.type) {
            case 1: {
                
                self.messageTypeLabel.text = @"系统消息";
                break;
            }
            case 2: {
                
                self.messageTypeLabel.text = @"反馈回复";
                break;
            }
            default: {
                
                self.messageTypeLabel.text = @"";
                break;
            }
        }
    }else {
        
        self.messageTypeLabel.text = @"";
    }
    
    // 获取时间格式
    if (model.pushTime) {
        
        self.timeLabel.text = [NSString stringWithFormat:@"%@" , [self formatTimeStamp:model.pushTime withTimeFormatter:@"MM/dd HH:mm"]];
    }else {
        
        self.timeLabel.text = @"";
    }
    
    // 通知内容
    if (![model.content isKindOfClass:[NSNull class]]) {
        
        self.contentLabel.text = [NSString stringWithFormat:@"通知:%@" , model.content];
    }else {
        
        self.contentLabel.text = @"通知:";
    }

}


/// 删除action
- (IBAction)deleteMsgAction:(UIButton *)sender {
    
    if (self.deleteMsgBlockAction) {
        self.deleteMsgBlockAction();
    }
}


/**
 *  将时间戳转为指定格式的时间
 */
- (NSString *)formatTimeStamp:(NSTimeInterval)timeStamp withTimeFormatter:(NSString *)timeFormatters
{
    //秒数
    NSTimeInterval interval = timeStamp / 1000.0;
    //date
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    //格式
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:timeFormatters];
    //时间
    NSString *timeStr = [format stringFromDate:date];
    
    return timeStr;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
